/*
 * Filename:    CostCoverController.java
 * Copyright:   2014 中国平安保险（集团）股份有限公司 版权所有
 * Company:     平安科技养老险及健康险系统开发部
 * Create at:   2014年9月29日
 */
package com.paic.mhis.hcpms.quota.settlement.web.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.paic.mhis.hcpms.quota.calculationreport.kpiinterface.dto.KpiConditionDTO;
import com.paic.mhis.hcpms.quota.settlement.biz.service.KpiChartService;
import com.paic.mhis.hcpms.quota.settlement.common.Constants;
import com.paic.mhis.hcpms.quota.settlement.common.KpiValueConst;
import com.paic.pafa.appclient.annotation.BizServicesProxy;
import com.pingan.um.client.util.StringUtil;

@Controller
@RequestMapping("/kpi/")
public class KpiChartController {

	@BizServicesProxy(beanName = "kpiChartService")
	private KpiChartService kpiChartService;

	@RequestMapping("getKpiChartValue.do")
	@ResponseBody
	public Map<String,Object> getKpiChartValue(@RequestBody Map<String,Object> map) {
		
		Map<String,Object> resultMap = new HashMap<String,Object>();
		
		List<Map<String,Object>> ids = (ArrayList<Map<String,Object>>) map.get("ids");// 复选框id
		
		String kpiId = (String) map.get("kpiId");// 需分析的指标code
		
		String dataType =  StringUtil.isNull(map.get("dataType")) ? "all" : map.get("dataType").toString();// 总住门点击类型
		
		String period  =  StringUtil.isNull(map.get("period")) ? "" : map.get("period").toString();   //统计期间维度
		//开始日期
		String startDate =  StringUtil.isNull(map.get("startDate")) ? "": map.get("startDate").toString();
		
		//结束日期
		String endDate =  StringUtil.isNull(map.get("endDate")) ? "": map.get("endDate").toString();
				
		if (StringUtil.isNull(period) || StringUtil.isEmpty(period)) {
			period = KpiValueConst.MONTH;
		} 
		String msg = "";
		if (StringUtil.isEmpty(startDate)) {
			msg = msg + "开始日期不能为空";
		}
		
		if (StringUtil.isEmpty(endDate)) {
			msg = msg + "结束日期不能为空";
		}
		
		if (StringUtil.isEmpty(kpiId)) {
			msg = msg + "指标不能为空";
		}
		if (null == ids || ids.size() == 0) {
			msg = msg + "id集合不能为空";
		}
		if (StringUtil.isEmpty(msg)) {
			KpiConditionDTO condition = new KpiConditionDTO();
			condition.setKpiTimeStart(startDate);
			condition.setKpiTimeEnd(endDate);
			condition.setPeriod(period);
			
			if (Constants.visitType_all.equals(dataType)) {
				condition.setVisitType(Constants.visitType_all_value);
			} 
			else if (Constants.visitType_hosp.equals(dataType)) {
				condition.setVisitType(Constants.visitType_hosp_value);
			} 
			else if (Constants.visitType_out.equals(dataType)) {
				condition.setVisitType(Constants.visitType_out_value);
			}
			resultMap = this.kpiChartService.getKpiChartValue(condition, ids, kpiId);
			
			resultMap.put("state", "0");
		}
		else {
			resultMap.put("state", "1");
			resultMap.put("msg", msg);
		}
		
		return resultMap;
	}
	
}
